import java.util.*;

class Trainee{
    public String name;
    public char sex;

    public Trainee(String name, char sex) {
        this.name = name;
        this.sex = sex;
    }

//    @Override
//    public String toString() {
//        return "姓名是：" + name +"；性别是：" + sex;
//    }
}
public class workwork {
    public static void t1(){
        Scanner sc = new Scanner(System.in);
        System.out.print("输入字符串：");
        String str = sc.next();
        char[] chars = str.toCharArray();
        Map<Character,Integer> map = new HashMap<>();
        for (char aChar : chars) {
            Integer value = map.get(aChar);
            if (value == null){
                map.put(aChar,1);
            }else {
                value++;
                map.put(aChar,value);
            }
        }
        //System.out.println(map);
        Set<Character> keyset = map.keySet();   //获取集合中所有的key值；
        Iterator<Character> iterator = keyset.iterator();
        while (iterator.hasNext()){
            Character next = iterator.next();
            System.out.println(next + "\t" + map.get(next));
        }

    }

    public static void t2(){
        Set set = new LinkedHashSet();
        set.add(new News("001","高考","哈哈"));
        set.add(new News("002","中考","嘿嘿"));
        set.add(new News("003","小考","呜呜"));
        System.out.print("高考标题数目为：" + set.size());
        System.out.println();
        Iterator iterator = set.iterator();
        while (iterator.hasNext()){
            System.out.println(iterator.next());
        }
        System.out.println("==============================");
        for (Object o : set) {
            System.out.println(o);
        }

    }

    public static void t3(){
        HashSet set = new HashSet();
        set.add(new Dog("欧欧","雪纳瑞"));
        set.add(new Dog("亚亚","拉布拉多"));
        set.add(new Dog("欧欧","拉布拉多"));
        set.add(new Dog("美美","雪纳瑞"));
        Iterator iterator = set.iterator();
        while (iterator.hasNext()){
            System.out.println(iterator.next());
        }
    }

    public static void t4(){
        Map<String,String> map = new HashMap<>();
        map.put("US","美利坚合众国");
        map.put("RU","俄罗斯联邦");
        map.put("CN","中华人民共和国");
        map.put("FR","法兰西共和国");
        System.out.println("CN对应的国家是：" + map.get("CN"));
        System.out.println("Map中共包含" + map.size() + "组数据");
        System.out.println("Map中包含FR的key吗？" + map.containsKey("FR"));
        map.remove("FR");
        System.out.println("Map中包含FR的key吗？" + map.containsKey("FR"));
        System.out.println(map);
        map.clear();
        System.out.println("已清空Map中数据！");
    }

    public static void t5(){
        Map<Integer,Dog> map = new HashMap<>();
        map.put(1,new Dog("欧欧","雪纳瑞"));
        map.put(2,new Dog("亚亚","拉布拉多"));
        map.put(3,new Dog("欧欧","拉布拉多"));
        map.put(4,new Dog("美美","雪纳瑞"));
        Iterator iterator = map.keySet().iterator();
        while (iterator.hasNext()){
            System.out.println(map.get(iterator.next()));
        }
        System.out.println("===============================");
        for (Integer integer : map.keySet()) {
            System.out.println(map.get(integer));
        }
    }

    public static void t6(){
        Map<String,Trainee> map = new HashMap<>();
        map.put("jack", new Trainee("杰克",'男'));
        map.put("rose", new Trainee("肉丝",'女'));
        map.put("tom", new Trainee("汤姆",'男'));
        if (map.containsKey("jack")){
            System.out.println("jack对应的学员" + map.get("jack"));
        }else {
            System.out.println("没有这个学员");
        }

    }

    public static void t7(){
        List<Dog> list = new ArrayList<>();
        list.add(new Dog("欧欧","雪纳瑞"));
        list.add(new Dog("亚亚","拉布拉多"));
        list.add(new Dog("欧欧","拉布拉多"));
        list.add(new Dog("美美","雪纳瑞"));
        Iterator<Dog> iterator = list.iterator();
        while (iterator.hasNext()){
            System.out.println(iterator.next());
        }
        System.out.println("====================");
        for (Dog dog : list) {
            System.out.println(dog);
        }

        System.out.println("====================");
        Map<Integer,Dog> map = new HashMap<>();
        map.put(1,new Dog("wu","雪纳瑞"));
        map.put(2,new Dog("wu","拉布拉多"));
        map.put(3,new Dog("wu","拉布拉多"));
        map.put(4,new Dog("wu","雪纳瑞"));
        Iterator<Integer> mapit = map.keySet().iterator();
        while (mapit.hasNext()){
            System.out.println(map.get(mapit.next()));
        }
        System.out.println("=================");
        for (Integer integer : map.keySet()) {
            System.out.println(map.get(integer));
        }
    }

    public static void t8(){
        Map<String,Trainee> map = new HashMap<>();
        map.put("jack", new Trainee("杰克",'男'));
        map.put("rose", new Trainee("肉丝",'女'));
        map.put("tom", new Trainee("汤姆",'男'));
        //键集
        System.out.println("键集:" + map.keySet());
        //值集
        System.out.print("值集:");
        for (String s : map.keySet()) {
            System.out.print(map.get(s));
        }
        System.out.println();
        System.out.println("键=值集合：" + map);
        if (map.containsKey("jack")){
            System.out.println("学员姓名：" + map.get("jack").name);
        }
    }

    public static void main(String[] args) {
        t8();
    }
}
